package com.c2soft.ncmxtradeX.controller;

import java.net.URI;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lombok.extern.log4j.Log4j2;

import org.codehaus.plexus.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import com.c2soft.ncmxtradeX.util.JsonUtil;


@Log4j2
@Controller
public class UserListController {
	
	@Value("#{systemProperties['ncmxServer.redirect.url']}")
	private String baseServerUrl;
	
	@Autowired
	private RestTemplate restTemplate;
	
	@RequestMapping(value = "/userList",method=RequestMethod.GET)
	
	public @ResponseBody List userList(HttpServletRequest req,HttpServletResponse resp) {
		
		
		String brokerId=req.getParameter("brokerName");
		URI redirectUrl= UriComponentsBuilder.fromUriString(baseServerUrl)
			    .path("userList")
			    .queryParam("brokeId", brokerId)
			    .build()
			    .toUri();
		
		resp.setContentType("application/json; charset=utf-8");
		List response=restTemplate.getForObject(redirectUrl, List.class);
		String[] appendArray={"{\"rows\":",response.toString(),"}"};//TODO: clean junk
		return response;
	}


}
